package com.wrupple.muba.catalogs.client.view.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasData;
import com.wrupple.muba.catalogs.client.view.DataView;
import com.wrupple.muba.widget.client.widgets.panels.PanelWithToolbar;
import com.wrupple.muba.widget.client.widgets.toolbar.ActionToolbar;

public class SimpleDataView<T> extends ResizeComposite implements DataView<T> {

	protected HasData<T> display;
	
	protected PanelWithToolbar main;
	
	private ActionToolbar toolbar;

	public SimpleDataView(HasData<T> display) {
		super();
		this.display = display;
		main = new PanelWithToolbar();
		main.getContentContainer().setWidget(Widget.asWidgetOrNull((IsWidget) display));
		initWidget(main);
	}
	

	@Override
	public void setAction(List<? extends HasClickHandlers> widgets) {
		if(toolbar==null && widgets!=null && !widgets.isEmpty()){
			this.toolbar = new ActionToolbar();
			List actions=widgets;
			toolbar.addActions(actions);
			main.addToolbar(toolbar);
		}
	}

	@Override
	public HasData<T> getDisplay() {
		return display;
	}

	@Override
	public List<T> getVisibleEntries() {
		return new ArrayList<T>((Collection<T>)display.getVisibleItems());
	}

	
	
}
